package com.lwl.controller.sds;

import com.github.pagehelper.PageInfo;
import com.lwl.entity.*;
import com.lwl.entity.sds.TSdsPlan;
import com.lwl.service.sds.TSdsPlanService;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.http.HttpSession;
import java.util.Date;

/**
 * (TSdsPlan)表控制层
 *
 * @author Lei
 * @since 2022-11-09 22:09:04
 */
@RestController
@RequestMapping("tSdsPlan")
public class TSdsPlanController {
    /**
     * 服务对象
     */
    @Autowired
    private TSdsPlanService tSdsPlanService;

    /**
     * 查询所有的测试计划
     * @return
     */
    @GetMapping("queryAll")
    public LayData queryAll(MyPage myPage, TSdsPlan tSdsPlan){
        PageInfo pageInfo = tSdsPlanService.queryAll(myPage,tSdsPlan);
        return new LayData(pageInfo);
    }

    /**
     *  添加/修改 测试计划
     */
    @PostMapping("addPlane")
    public LayData insertplane(TSdsPlan tSdsPlan, HttpSession session){
        Tuser user = (Tuser)session.getAttribute("user");
        tSdsPlan.setCreatetime(new Date());
        tSdsPlan.setUid(user.getId());
        return new LayData(tSdsPlanService.insertPlane(tSdsPlan));
    }

    /**
     * 根据邀请码查询对应的测试计划，如果已经有对应的邀请码，那就需要生成一个新的邀请码
     * @return
     */
    @PostMapping("selectCode")
    public LayData selectCode(TSdsPlan tSdsPlan){
        boolean status = tSdsPlanService.selectCode(tSdsPlan);
        return new LayData(status);
    }

    /**
     * 计划唯一性校验
     */
    @PostMapping("queryByPlaneName")
    public LayData queryByName(String planname){
        return  new LayData(tSdsPlanService.queryByName(planname));
    }

    /**
     * 用户登录做题时，根据邀请码查询测试计划的具体内容，用来判断是否在做题时间
     * @return
     */
    @GetMapping("getByCode")
    public LayData getByCode(TSdsPlan tSdsPlan){
        TSdsPlan tSdsPlan1 = tSdsPlanService.getByCode(tSdsPlan);
        return new LayData(tSdsPlan1);
    }

    /**
     * 根据测试计划id检验回访时测试计划是否正确
     */
    @PostMapping("checkPlanId")
    public LayData checkPlanId(String planid){
        boolean status = tSdsPlanService.checkPlanId(planid);
        return new LayData(status);
    }

}
